﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace ZX.Web.UI.Controls.ControlBind
{
    public static class DropDownListControl
    {
        /// <summary>
        /// 绑定下拉框通用方法
        /// </summary>
        /// <param name="ctrl">下拉框控件名</param>
        /// <param name="ds">数据源</param>
        /// <param name="Text">显示值</param>
        /// <param name="Value">绑定值</param>
        public static void DropDataSourceBind(DropDownList ctrl, object objDs, string strText, string strValue)
        {
            if (objDs != null)
            {
                ctrl.DataSource = objDs;
                ctrl.DataTextField = strText;
                ctrl.DataValueField = strValue;
                ctrl.DataBind();
            }
        }
        /// <summary>
        /// 下拉框选中项
        /// </summary>
        /// <param name="ctrl">下拉框</param>
        /// <param name="strValue">显示值</param>
        public static void DropDownListSelect(DropDownList ctrl, string strValue)
        {
            ListItem listItems = ctrl.Items.FindByValue(strValue);
            if (listItems != null)
            {
                int iIndex = ctrl.Items.IndexOf(listItems);
                ctrl.SelectedIndex = iIndex;
            }
        }
    }
}
